package com.haiyuancloud.base.menu.controller;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author haiyuan
 */
@Slf4j
@RestController
@RequestMapping
@RequiredArgsConstructor
public class IndexController {

    @ResponseBody
    @GetMapping("user")
    public Principal currentUser(Principal principal) {
        return principal;
    }

    @GetMapping("success/{src}")
    public void loginSuccess(@PathVariable String src, HttpServletRequest request) {
    }


    /**
     * 按风格返回时间格式
     *
     * @param sTyle 风格
     * @return 返回时间格式
     */
    public static String getNowTimeInStyle(String sTyle) {
        Calendar c = Calendar.getInstance();
        if (null == sTyle || "".equalsIgnoreCase(sTyle)) {
            sTyle = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat df = new SimpleDateFormat(sTyle);
        return df.format(c.getTime());
    }
}
